package com.caocaog.market.entity.dto;

import com.caocaog.market.entity.GoodsBase;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.common.system.base.entity.groups.UpdateGroup;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

/**
 * 商品信息数据传输对象
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class GoodsDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotNull(message = "更新时，id不能为空", groups = {UpdateGroup.class})
    @ApiModelProperty(value = "ID")
    private String id;

    @NotNull(message = "商品全称不能为空")
    @ApiModelProperty(value = "商品全称")
    private String name;

    @ApiModelProperty(value = "商品简称")
    private String shortName;

    @Dict(dictTable = "mk_goods_sort", dicText = "name", dicCode = "id")
    @ApiModelProperty(value = "商品分类")
    private String sorts;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @NotNull(message = "商品原价不能为空")
    @Min(value = 0, message = "商品原价不能小于0元")
    @ApiModelProperty(value = "商品原价")
    private String originalPrice;

    @NotNull(message = "商品现价不能为空")
    @Min(value = 0, message = "商品现价不能小于0元")
    @ApiModelProperty(value = "商品现价")
    private String presentPrice;

    @ApiModelProperty(value = "商品代码")
    private String code;

    @ApiModelProperty(value = "商品图片")
    private String picture;

    @ApiModelProperty(value = "商品描述")
    private String description;

    @Deprecated
    @ApiModelProperty(value = "商品短描述")
    private String shortDescription;

    @ApiModelProperty(value = "商品上下架状态")
    private String status;

    @ApiModelProperty(value = "是否首页展示")
    private String isIndex;

    @ApiModelProperty(value = "是否热门商品")
    private String isHot;

    @ApiModelProperty(value = "是否单点不送")
    private String oneNoDelivery;

    @ApiModelProperty(value = "浏览次数")
    private Integer visitNum;

    @ApiModelProperty(value = "销售数量")
    private Integer saleNum;

    @ApiModelProperty(value = "关联店铺表（mk_shop_basic表中的id字段）；店铺id")
    @Dict(dictTable = "mk_shop_basic", dicCode = "id", dicText = "name")
    private String shopId;

    @ApiModelProperty(value = "起售数量")
    private Integer salesQuantity;

    @ApiModelProperty(value = "商品详情")
    private String goodDetail;

    @ApiModelProperty(value = "商品供应商")
    private String goodBrand;

    @ApiModelProperty("商品销量")
    private Integer textMonthly;

    @NotNull(message = "至少添加一个规格")
    @Size(min = 1, message = "至少添加一个规格")
    @Valid
    @ApiModelProperty(value = "商品规格数据传输对象")
    private List<GoodsSpecDTO> goodsSpecificationsVoList;

    @Valid
    @ApiModelProperty(value = "商品属性数据传输对象")
    private List<GoodsAttrDTO> goodsAttributeVoList;

    public GoodsBase toGoodsBase() {
        return new GoodsBase()
                .setGoodBrand(this.goodBrand)
                .setId(this.id)
                .setName(this.name)
                .setShortName(this.shortName)
                .setSorts(this.sorts)
                .setSort(this.sort)
                .setOriginalPrice(this.originalPrice)
                .setPresentPrice(this.presentPrice)
                .setCode(this.code)
                .setPicture(this.picture)
                .setDescription(this.description)
                .setShortDescription(this.shortDescription)
                .setStatus(this.status)
                .setSaleNum(this.saleNum)
                .setIsIndex(this.isIndex)
                .setIsHot(this.isHot)
                .setOneNoDelivery(this.oneNoDelivery)
                .setVisitNum(this.visitNum)
                .setSaleNum(this.saleNum)
                .setShopId(this.shopId)
                .setGoodDetail(this.goodDetail)
                .setSalesQuantity(this.salesQuantity);
    }
}
